<?php
class Customer_Models_Dao_Pdo_Mysql_Customer extends Tomato_Model_Dao
    implements Customer_Models_Interface_Customer
{
    public function convert($entity)
    {
        return new Customer_Models_Customer($entity);
    }

    public function getById($id){
        $select = $this->_conn
                        ->select()
                        ->from(array('u' => $this->_prefix.'core_user'),array('as_user_id' => 'user_id', 'role_id', 'user_name', 'full_name', 'email'))
                        ->joinLeft(array('c' => $this->_prefix.'customer'),"u.user_id = c.user_id")
                        ->where("u.user_id = ?",$id)
                        ->limit(1);
		                        
        $rowset = $select->query()->fetchAll();
        $cus = new Tomato_Model_RecordSet($rowset, $this);
        return (count($cus) == 0) ? null : $cus[0];
    }

    public function getRoleByName($name){
        $row = $this->_conn
                    ->select()
                    ->from(array('r' => $this->_prefix . 'core_role'))
                    ->where('r.name = ?', $name)
                    ->limit(1)
                    ->query()
                    ->fetch();
        return (null == $row) ? null : new Core_Models_Role($row);
    }
}
